package ink.lovejinhu.leetcode;

/**
 * @author jinhu
 * created 2021-07-06 9:04
 */
public class Solution_0190 {
    public int reverseBits(int n) {
        int[] res = new int[32];
        int cur = res.length - 1;
        while (n / 2 > 0 || n % 2 > 0) {
            res[cur] = n % 2;
            cur--;
            n /= 2;
        }
        int result = 0;
        for (int i = res.length - 1; i >= 0; i--) {
            result = result * 2 + res[i];

        }

        return result;

    }
    public int reverseBits1(int n) {
        int rev = 0;
        for (int i = 0; i < 32 && n != 0; ++i) {
            rev |= (n & 1) << (31 - i);
            n >>>= 1;
        }
        return rev;
    }

    public static void main(String[] args) {
        Solution_0190 solution_0190 = new Solution_0190();
        System.out.println(solution_0190.reverseBits(43261596));
        solution_0190.reverseBits(1);
        //   System.out.println(solution_0190.reverseBits(43261596));
      //  int i = solution_0190.reverseBits1(4294967293);
        String s = new Integer(11).toString(2);
        System.out.println(s);
    }
}
